﻿using MediatR;
using Traceability.APP.Applications.Commands.YangZhi;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.APP.Applications.CommandHandlers.YangZhi
{
    public class FarmCompanyQueryCommandHandler : IRequestHandler<FarmCompanyQueryCommand, APIResult<FarmCompanyModel>>
    {
        private readonly IBaseRepository<FarmCompanyModel> _farmcomRepository;

        public FarmCompanyQueryCommandHandler(IBaseRepository<FarmCompanyModel> farmcomRepository)
        {
            _farmcomRepository = farmcomRepository;
        }

        public Task<APIResult<FarmCompanyModel>> Handle(FarmCompanyQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<FarmCompanyModel> result = new APIResult<FarmCompanyModel>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _farmcomRepository.GetAll().FirstOrDefault(x => x.Batch == request.Batch);
            result.Data = m;
            return Task.FromResult(result);
        }
    }
}
